package group.raber.saber.model;

import group.raber.saber.kit.ListKit;
import group.raber.saber.lang.DataBox;

import java.io.Serializable;
import java.util.List;

/**
 * 节点条目,一般用来组织具有上下级关系的可伸缩的节点
 * Created by tisir<yangsong158@qq.com> on 2017-06-06
 */
public class NodeEntry extends DataBox implements Serializable,Cloneable{

	private static final long serialVersionUID = 5443667887753869721L;
	
	public static final String KEY_PARENT = "parent";
    public static final String KEY_CHILDREN = "children";

    public NodeEntry getParent() {
        return this.xGetObject(KEY_PARENT,NodeEntry.class);
    }

    public void setParent(NodeEntry parent) {
        this.xPut(KEY_PARENT,parent);
    }

    @SuppressWarnings("unchecked")
	public List<NodeEntry> getChildren() {
        return (List<NodeEntry>)this.xGetObject(KEY_CHILDREN,List.class);
    }

    public void setChildren(List<NodeEntry> children) {
        this.xPut(KEY_CHILDREN,children);
    }

    public NodeEntry addChild(NodeEntry nodeEntry){
        List<NodeEntry> children = getChildren();
        if(children==null){
            children = ListKit.newArrayList();
            setChildren(children);
        }
        children.add(nodeEntry);

        return this;
    }
}
